// Test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "SharedHandleTestSuite.h"
#include "SimpleEventTestSuite.h"
#include "SimpleCriticalSectionTestSuite.h"
#include "SimpleSocketTestSuite.h"
#include "ThreadTestSuite.h"
#include "SocketServerTestSuite.h"
#include "TimeValueTestSuite.h"
#include "ActiveObjectPortTestSuite.h"
#include "RoomTemplatesTestSuite.h"
#include "TimerTestSuite.h"
#include "SendMessageErrorTestSuite.h"
#include "MessageReplyTestSuite.h"
#include "RetrySenderTestSuite.h"
#include "DynamicBindingTestSuite.h"
#include "ExtraAoEventsTestSuite.h"
#include "ActiveObjectTestSuite.h"
#include "RemoteBindingTestSuite.h"

void PurecallHandler(void)
{
	ASSERT(false);
	throw std::runtime_error("purecall");
}

// The main application processes all testsuites that you manually add below.
// All output from the tests is redirected to an NUnit Based XML file.
int main(int argc, char* argv[])
{
	::_set_purecall_handler(PurecallHandler);

	std::string outputfilepath = "";
	bool bXml = false;
	
	try
	{
		if(argc > 1)
		{
			// [0] is always the executable itself.
			outputfilepath = argv[1];
			bXml = true;
		}

		Test::Suite ts;
		ts.add(std::auto_ptr<Test::Suite>(new CO::SpiFoundation::RoomFW::SharedHandleTestSuite));
		ts.add(std::auto_ptr<Test::Suite>(new CO::SpiFoundation::RoomFW::SimpleEventTestSuite));
		ts.add(std::auto_ptr<Test::Suite>(new CO::SpiFoundation::RoomFW::SimpleCriticalSectionTestSuite));
		ts.add(std::auto_ptr<Test::Suite>(new CO::SpiFoundation::RoomFW::TimeValueTestSuite));
		ts.add(std::auto_ptr<Test::Suite>(new CO::SpiFoundation::RoomFW::ThreadTestSuite));
		ts.add(std::auto_ptr<Test::Suite>(new CO::SpiFoundation::RoomFW::TimerTestSuite));
		ts.add(std::auto_ptr<Test::Suite>(new CO::SpiFoundation::RoomFW::ActiveObjectPortTestSuite));
		ts.add(std::auto_ptr<Test::Suite>(new CO::SpiFoundation::RoomFW::RoomTemplatesTestSuite));
		ts.add(std::auto_ptr<Test::Suite>(new CO::SpiFoundation::RoomFW::SendMessageErrorTestSuite));
		ts.add(std::auto_ptr<Test::Suite>(new CO::SpiFoundation::RoomFW::MessageReplyTestSuite));
		ts.add(std::auto_ptr<Test::Suite>(new CO::SpiFoundation::RoomFW::RetrySenderTestSuite));
		ts.add(std::auto_ptr<Test::Suite>(new ActiveObjectTestSuite));
		ts.add(std::auto_ptr<Test::Suite>(new CO::SpiFoundation::RoomFW::ExtraAoEventsTestSuite));
		ts.add(std::auto_ptr<Test::Suite>(new CO::SpiFoundation::RoomFW::DynamicBindingTestSuite));
		ts.add(std::auto_ptr<Test::Suite>(new CO::SpiFoundation::RoomFW::SocketServerTestSuite));
#if 0
		ts.add(std::auto_ptr<Test::Suite>(new CO::SpiFoundation::RoomFW::SimpleSocketTestSuite));
#endif
		ts.add(std::auto_ptr<Test::Suite>(new CO::SpiFoundation::RoomFW::RemoteBindingTestSuite));

		std::ofstream theStream;
		if(outputfilepath.length() > 0)
			theStream.open(outputfilepath.c_str());

		Test::Output* pOutput = NULL;
		
		if(bXml)
			pOutput = new Test::XmlOutput(theStream);
		else 
			pOutput = new Test::TextOutput(Test::TextOutput::Verbose);

		std::auto_ptr<Test::Output> output = std::auto_ptr<Test::Output>(pOutput);
		ts.run(*output, false);
		theStream.close();
	}
	catch (...)
	{
		std::cout << "unexpected exception encountered in CPPTestRunner\n";
	}

	if(!bXml)
	{
		std::cout << "Press a key to exit!\n";
		_getch();
	}

	return 0;
}
